%Figure 1
% Average portfolio yields, excess spreads, and charge-off rates
% This figure shows the average portfolio yield, excess spread, and charge-
% off rates for the issuers in the sample, where the averages are taken over
% the average values for each issuer in the sample for a given month.

clear; clc;

% load data
load("Data_Figure_01");


fig1 = figure('NumberTitle', 'Off', 'Name', 'Figure 1');

figOrientation = 'portrait';
figWidth = 8.0; %set directly, margins not used here
figHeight = 8.0; %set directly, margins not used here

%figure size on screen, 50% scaled but same aspect ratio
set(fig1,'Units','inch');
set(fig1,'Position',[0 0 figWidth figHeight]);
movegui(fig1,'center')

%set figure size on printed page
set(fig1,'PaperUnits', 'centimeters');
%set(fig1,'PaperSize', [paperWidth paperHeight]);
%set(fig1,'PaperPosition',[leftMargin bottomMargin figWidth figHeight]);
set(fig1,'PaperSize', [figWidth figHeight]);
set(fig1,'PaperPosition',[0 0 figWidth figHeight]);
set(fig1,'PaperOrientation',figOrientation);
set(fig1,'InvertHardcopy','on');



plotData = PortfYldExspreadChrgoff;
subplot_er(3,1,1);
ax = gca;
ax.PlotBoxAspectRatio = [1,0.35,0.35];
plot_1 = plot(datenum(plotData.Date),plotData.PortfYld);
set(plot_1, 'LineStyle', '-', 'Color', 'b' , 'LineWidth', 1.00);
minX = min(datenum(plotData.Date));
maxX = max(datenum(plotData.Date));
xlim([minX-0.025 maxX+0.025])
dateaxis
set(gca,'XTick',datenum([...
    'Jan-1-2002'; ...
    'Jan-1-2006'; ...
    'Jan-1-2010'; ...
    'Jan-1-2014'; ...
    'Jan-1-2018']));
set(gca,'XTickLabel',[...
    '2002';...
    '2006';...
    '2010';...
    '2014';...
    '2018'])
ylabel('Percent')
title('Portfolio Yield','FontWeight','normal')
legend 'off';
grid 'on';
box 'on';
set(gcf, 'Color', [1,1,1]);


subplot_er(3,1,2);
ax = gca;
ax.PlotBoxAspectRatio = [1,0.35,0.35];
plot_2 = plot(datenum(plotData.Date),plotData.ExcessSpread);
set(plot_2, 'LineStyle', '-', 'Color', 'b' , 'LineWidth', 1.00);
minX = min(datenum(plotData.Date));
maxX = max(datenum(plotData.Date));
xlim([minX-0.025 maxX+0.025])
dateaxis
set(gca,'XTick',datenum([...
    'Jan-1-2002'; ...
    'Jan-1-2006'; ...
    'Jan-1-2010'; ...
    'Jan-1-2014'; ...
    'Jan-1-2018']));
set(gca,'XTickLabel',[...
    '2002';...
    '2006';...
    '2010';...
    '2014';...
    '2018'])
ylabel('Percent'); 
title('Excess Spread','FontWeight','normal')
legend 'off';
grid 'on';
box 'on';
set(gcf, 'Color', [1,1,1]);



subplot_er(3,1,3);
ax = gca;
ax.PlotBoxAspectRatio = [1,0.35,0.35];
plot_2 = plot(datenum(plotData.Date),plotData.ChargeOffs1m);
set(plot_2, 'LineStyle', '-', 'Color', 'b' , 'LineWidth', 1.00);
minX = min(datenum(plotData.Date));
maxX = max(datenum(plotData.Date));
xlim([minX-0.025 maxX+0.025])
dateaxis
set(gca,'XTick',datenum([...
    'Jan-1-2002'; ...
    'Jan-1-2006'; ...
    'Jan-1-2010'; ...
    'Jan-1-2014'; ...
    'Jan-1-2018']));
set(gca,'XTickLabel',[...
    '2002';...
    '2006';...
    '2010';...
    '2014';...
    '2018'])
ylabel('Percent');
title('Charge-Off Rate','FontWeight','normal')
legend 'off';
grid 'on';
box 'on';
set(gcf, 'Color', [1,1,1]);

